package com.example.day7;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.day7.sql.Sql;

public class InActivity extends AppCompatActivity {

    private Button mBu;
    private EditText mEdName;
    private EditText mEdTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_in);
        initViews();
    }

    private void initViews() {
        mBu = findViewById(R.id.bu);
        mEdName = findViewById(R.id.ed_name);
        mEdTitle = findViewById(R.id.ed_title);
        Sql sql = new Sql(this);
        mBu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = mEdName.getText().toString();
                String title = mEdTitle.getText().toString();
                if (!name.isEmpty()&&!title.isEmpty()){
                    sql.inserUser(name,title);
                    Toast.makeText(InActivity.this,"保存成功",Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(InActivity.this,"内容或标签为空",Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
